package net.sf.calibur.transport.message;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

import net.sf.calibur.transport.TransportException;

public class MessageHead {
	public final static int NONE = 0;
	public final static int SIMPLE = 1;
	
	public static MessageHead readMessageHead(int type, InputStream input) throws IOException {
		switch (type) {
		case NONE: // 类型0，无报文头
			return null;
			
		case SIMPLE: // 类型1，8个字节（long）的客户端时间戳
			MessageHead head = new MessageHead();
			DataInputStream dis = new DataInputStream(input);
			head.setClientTimestamp(dis.readLong());
			return head;
			
		default:
			throw new TransportException("Unknown message head type "
					+ type);
			
		}
	}
	
	private long clientTimestamp;
	
	public MessageHead() {
	}

	public long getClientTimestamp() {
		return clientTimestamp;
	}

	public void setClientTimestamp(long clientTimestamp) {
		this.clientTimestamp = clientTimestamp;
	}
}
